{include file="public/head"/}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">{if $action=='edit'}编辑{else /}添加{/if}字段</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-form" wid100 lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">字段类型</label>
                            <div class="layui-input-inline">
                                <select id="type" name="type" lay-filter="type" {if $action=='edit'}disabled{/if} class="required" lay-verify="required">
                                    <option value='' >请选择字段类型</option>
                                    {volist name="type" id="vo"}
                                    <option {if($info.type eq $vo.name)} selected{/if} value="{$vo.name}">{$vo.title}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">字段名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="field" value="{$info.field}"  {if in_array($info.field,$disabled)}disabled=""{/if} lay-verify="required" placeholder="必填：字段名" autocomplete="off" class="layui-input {if in_array($info.field,$disabled)}layui-disabled{/if}">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">别名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" value="{$info.name}" lay-verify="required" placeholder="必填：别名" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">字段设置</label>
                            <div class="layui-input-block">
                                <div class="layui-col-lg12" id="field_setup">

                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">验证规则</label>
                            <div class="layui-input-inline">
                                <select name="pattern" lay-verify="required">
                                    {volist name="pattern" id="vo"}
                                    <option {if ($info.pattern eq $vo.name)}selected{/if} value="{$vo.name}">{$vo.title}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">class名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="class" value="{$info.class}" lay-verify="required" placeholder="请输入class名称" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">是否必填</label>
                                <div class="layui-input-inline">
                                    <input type="radio" name="required" {if($info.required eq 1)}checked{/if} value="1" title="是">
                                    <input type="radio" name="required" {if($info.required eq 0)}checked{/if} value="0" title="否">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">字符长度</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="minlength" value="{$info.minlength}" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="maxlength" value="{$info.maxlength}" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-row layui-col-space10 layui-form-item">
                            <div class="layui-col-lg6">
                                <label class="layui-form-label">错误信息</label>
                                <div class="layui-input-block">
                                    <input type="text" name="errormsg" value="{$info.errormsg}" placeholder="验证失败错误信息" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="modelid" value="{:input('mid')}">
                                <input type="hidden" name="id" value="{:input('id')}">
                                <input type="hidden" name="oldfield" value="{$info.field}">
                                <button class="layui-btn" lay-submit lay-filter="{if $action=='edit'}edit-btn{else /}add-btn{/if}">确认保存</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/foot"/}
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script>
    layui.config({
        base: '__LAYADMIN__/',
        version: true
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','field','form'],function(){
        var $ = layui.$,form = layui.form;
        {if $info}
        var type = '{$info.type}';
        var name = '{$info.field}';
        var id = '{$info.id}';
        var modelid = '{$info.modelid}';
        var url = "{:url('fieldType')}?type=" + type + "&name=" + name+"&id="+id+"&modelid="+modelid;
        field_setting(type, url);
        {/if}
        form.on('select(type)', function(type){
            var typeVal = type.value;
            var url = "{:url('fieldType')}?type=" + typeVal;
            field_setting(type, url);
        });
        function field_setting(type,url) {
            $.ajax({
                type: "POST",
                url: url,
                beforeSend:function(){
                    $('#field_setup').html('<i class="fa fa-spinner fa-spin fa-fw"></i>');
                    form.render()
                },
                success: function(msg){
                    $('#field_setup').html(msg);
                    form.render()
                },
                complete:function(){
                },
                error:function(){
                }
            });
        }
    });
</script>
</body>
</html>